/*
 *  MiloNetwork.cpp
 *  Milovo04alfa00
 *
 *  Created by Luca on 20/11/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "Milovo.h"

void ExtractNetworkForPajek(string StrPath, Agents *tmpTabAgents, Recipes *tmpTabRecipes, Artifacts *tmpTabArtifacts, Mil_Int tmpCurrentStep)
{
	ostringstream strCurrentStep;
	strCurrentStep << tmpCurrentStep;
	ofstream fid_ArtifactsNetwork;
	string strNetFile = StrPath + "ArtifactsNetworkStep" + strCurrentStep.str() + ".net";
	fid_ArtifactsNetwork.open(strNetFile.c_str(), ios::out);
	
	fid_ArtifactsNetwork << "*Vertices " << tmpTabArtifacts->size() << endl;
	for(Artifacts::iterator tmpTabArtifactsIter = tmpTabArtifacts->begin(); tmpTabArtifactsIter != tmpTabArtifacts->end(); tmpTabArtifactsIter++)
		fid_ArtifactsNetwork << tmpTabArtifactsIter->second.GetID() << " \"" << tmpTabArtifactsIter->second.GetName() << "\"" << endl;
	
	fid_ArtifactsNetwork << "*Arcs " << endl;
	for(Recipes::iterator tmpTabRecipesIter = tmpTabRecipes->begin(); tmpTabRecipesIter != tmpTabRecipes->end(); tmpTabRecipesIter++)
	{
		for(list<Mil_Int>::iterator LinksIDArtifactsIter = tmpTabRecipesIter->second.LinksIDArtifacts.begin(); LinksIDArtifactsIter != tmpTabRecipesIter->second.LinksIDArtifacts.end(); LinksIDArtifactsIter++)
		{
			Mil_Int tmpIDArtifactInputForPajek = *LinksIDArtifactsIter;
			Mil_Int tmpIDArtifactOutputForPajek = tmpTabRecipesIter->second.GetIDArtifactOutput();
			fid_ArtifactsNetwork << tmpIDArtifactInputForPajek << " " << tmpIDArtifactOutputForPajek << " 1" << endl;
		}
	}
	fid_ArtifactsNetwork.close();
}

